#ifndef _GAME_CONFIG_MANAGER_H_
#define _GAME_CONFIG_MANAGER_H_

#include "Define.h"
#include "LogEx.h"
#include <vector>
#include <string>

struct ConnectItem
{
    ConnectItem() : serverid(0), ip(""), port(0), name("")
    {}

    bool Valid()
    {
        return ((serverid!=0) && (ip!="") && (port!=0));
    }

    s32 serverid;
    std::string ip;
    s32 port;
	std::string name;
};

struct ServerConfig
{
	ServerConfig() : 
		id(-1), ip(""), port(0), gameId(-1),
		ioServiceCount(0), useWorkerEvent(false), eventWorkerCount(0), eventQueueSize(0),
		connCount(0), szSend(0), szRecv(0), 
		rpcConnCount(0), rpcSzSend(0), rpcSzRecv(0), heartBeatTime(0)
	{}

    s32 id;
	std::string ip;
    s32 port;
	s32 gameId;

    s32 ioServiceCount;
    bool useWorkerEvent;
    s32 eventWorkerCount;
    s32 eventQueueSize;

    s32 connCount;
    s32 szSend;
    s32 szRecv;

    s32 rpcConnCount;
    s32 rpcSzSend;
    s32 rpcSzRecv;
    
    s32 heartBeatTime;
};

struct LogConfig
{
	LogConfig() : 
		file("game.log"), 
		minLevel(SGLib::CLogExManager::E_LogLevel_Debug),
		maxLevel(SGLib::CLogExManager::E_LogLevel_Error),
		rollingMode(SGLib::CLogExManager::E_LogMode_Hour)
	{}

	std::string file;
	s32 minLevel;
	s32 maxLevel;
	s32 rollingMode;
};

class CGameConfigManager
{
    SINGLETON_CLASS_DEFINE(CGameConfigManager);

public:
    void Load(const std::string &cfgfile);
	void ReloadLogConfig(const std::string &cfgfile);

	const ServerConfig& GetServerConfig();
	const LogConfig& GetLogConfig();

    s32 GetConnectCount();
    const ConnectItem* GetConnectItem(s32 idx);
    s32 GetServerId(const char *ip, s32 port);

	static s32 s_dbserverId;

private:
    bool _FindConnectItem(s32 serverid);

private:
	ServerConfig m_serverCfg;
	LogConfig m_logCfg;
    std::vector<ConnectItem> m_connItems;
};

#endif

